<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                常见问题信息
            </h1>
        </section>
        <div class="content">
            <div class="row">
                <div class="col-md-9">
                    <div class="box box-primary" style="overflow:hidden">
                        <form id="postForm" class="form-horizontal" autocomplete="off">
                            <input type="hidden" name="id" value="${entity.id}">
                            <div class="box-body" style="padding-top:30px">
                                <div class="form-group">
                                    <label for="selectCategory" class="col-sm-2 control-label">分类</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible" id="selectCategory"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true" name="categoryId">
                                            <option value="0" <c:if test="${entity.categoryId==0}">selected="selected"</c:if>>请选择</option>
                                            <option value="1" <c:if test="${entity.categoryId==1}">selected="selected"</c:if>>问题</option>
                                            <option value="2" <c:if test="${entity.categoryId==2}">selected="selected"</c:if>>常见问题</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputTitle" class="col-sm-2 control-label">标题</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputTitle"
                                               name="title" value="${entity.title}" placeholder="请输入标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="content" class="col-sm-2 control-label">内容</label>
                                    <div class="col-sm-5">
                                        <script type="text/plain" id="content" name="content">${entity.content}</script>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectIsStatis" class="col-sm-2 control-label">状态</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible" id="selectIsStatis"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true" name="isStatis">
                                            <option value="0" <c:if test="${entity.isStatis==0}">selected="selected"</c:if>>未发布</option>
                                            <option value="1" <c:if test="${entity.isStatis==1}">selected="selected"</c:if>>发布</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer">
                                <div class="col-sm-2"></div>
                                <button type="button" class="btn btn-info" onclick="submitForm()">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@ include file="/commons/script.jsp" %>
    <script charset="utf-8" src="${ctx}/ueditor/ueditor.config.js"></script>
    <script charset="utf-8" src="${ctx}/ueditor/ueditor.all.min.js"></script>
    <script charset="utf-8" src="${ctx}/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        var ue = UE.getEditor('content',{
            initialFrameWidth:700,
            initialFrameHeight:300,
            wordCount:true,
            elementPathEnabled:false
        });

        function submitForm() {
            var id = $('#postForm').find('input[name=id]').val();
            var url = null;
            if (id == null || id == "") {
                url = "${ctx}/problem/saveProblem?action=add";
            } else {
                url = "${ctx}/problem/saveProblem?action=update";
            }
            $.ajax({
                cache: false,
                type: "post",
                url: url,
                data: $('#postForm').serialize(),// formid
                error: function () {
                    alert("系统异常");
                },
                success: function (data) {
                    if (data !== null) {
                        if (data == 0) {
                            //修改失败
                            alert('失败');
                        } else {
                            //添加/修改成功
                            alert('成功');
                            window.location.href="${ctx}/problem/listProblem";
                        }
                    }
                }
            });
        }
    </script>
</body>
</html>
